//package com.dotflat.satistics.datasource;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
//import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//import org.springframework.transaction.support.TransactionTemplate;
//
//import javax.persistence.EntityManagerFactory;
//import javax.sql.DataSource;
//
///**
// * *******************************
// * Created by Tim.
// * form com.matt
// * on 2018/7/3
// * *******************************
// */
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories(
//        entityManagerFactoryRef = "crmEntityManagerFactory",
//        basePackages = {"com.dotflat.satistics.repository.crm"}
//)
//public class CrmDataSourceConfig {
//
//    @Autowired
//    private JpaProperties jpaProperties;
//
//    @Bean(name = "crmDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource")
//    public DataSource dataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "crmEntityManagerFactory")
//    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
//            EntityManagerFactoryBuilder builder,
//            @Qualifier("crmDataSource") DataSource dataSource) {
//
//        return builder
//                .dataSource(dataSource)
//                .packages("com.dotflat.satistics.repository.crm")
//                .properties(jpaProperties.getHibernateProperties(dataSource))
//                .persistenceUnit("crm")
//                .build();
//    }
//
//
//    /**
//     * 事务管理对象
//     * @return
//     */
//    @Bean(name = "crmTransactionManager")
//    public PlatformTransactionManager transactionManager(
//            @Qualifier("crmEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
//        return new JpaTransactionManager(entityManagerFactory);
//    }
//
//    @Bean(name = "crmJdbcTemplate")
//    public JdbcTemplate jdbcTemplate(){
//        return new JdbcTemplate(dataSource());
//    }
//
//    @Bean
//    public TransactionTemplate transactionTemplate(PlatformTransactionManager platformTransactionManager){
//        return new TransactionTemplate(platformTransactionManager);
//    }
//}
